package org.apache.derby.iapi.util;

import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;


public class PropertiesMapFromDictionary extends Dictionary {
	private PropertiesMap propMap;
	
	public PropertiesMapFromDictionary() {
		propMap = new PropertiesMap();
	}

	public Enumeration elements() {
		Hashtable hashTable = new Hashtable();
		
		for(Iterator itElements = propMap.elements(); itElements.hasNext(); ) {
			String temp = (String) itElements.next();
			hashTable.put(temp, propMap.get((String) temp));
		}
		
		return hashTable.elements();
	}

	public Object get(Object arg0) {
		return propMap.get((String) arg0);
	}

	public boolean isEmpty() {
		return propMap.isEmpty();
	}

	public Enumeration keys() {
		Hashtable hashTable = new Hashtable();
		
		for(Iterator itElements = propMap.keys(); itElements.hasNext(); ) {
			String temp = (String) itElements.next();
			hashTable.put(temp, propMap.get((String) temp));
		}
		
		return hashTable.keys();
	}

	public Object put(Object arg0, Object arg1) {
		return propMap.put(arg0, arg1);
	}

	public Object remove(Object arg0) {
		return propMap.remove(arg0);
	}

	public int size() {
		return propMap.size();
	}

	/**
	 * Search for the value linked by the specified key.
	 * 
	 * @param key
	 *            The key that you want to know the value.
	 * @return The value of the key, or "null" if the key is not found.
	 */
	public String getProperty(String chave) {
		return ((String) propMap.get(chave));
	}
	
	/**
	 * Search for the value with the specified key. If the key is not found in
	 * the map, then returns the default value provided.
	 * 
	 * @param key
	 *            - The key that you want to know the value.
	 * @param defaultValue
	 *            - One default value to be returned if the key doesn't exists.
	 * @return The value of the key, or the default value
	 */
	public String getProperty(String chave, String defaultValue) {
		return propMap.getProperty(chave, defaultValue);
	}
	
	/**
	 * Returns an Iterator of all keys in this HashMap.
	 * 
	 * @return An Iterator with all the keys contained in this HashMap.
	 */
	public Iterator propertyNames() {
		return propMap.propertyNames();
	}
	
	public Object setProperty(String key, String value) {
		return propMap.setProperty(key, value);
	}
	
	public PropertiesMap getPropertiesMap() {
		return propMap;
	}
}
